1   /*
2    * Copyright (C) 2007 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect;
18  
19  import com.google.common.annotations.GwtCompatible;
20  import com.google.common.collect.testing.MapInterfaceTest;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /** @author George van den Driessche */
26  @GwtCompatible
27  public class ConstrainedMapImplementsMapTest
28      extends MapInterfaceTest<String, Integer> {
29  
30    public ConstrainedMapImplementsMapTest() {
31      super(true, true, true, true, true);
32    }
33  
34    @Override protected Map<String, Integer> makeEmptyMap() {
35      return MapConstraints.constrainedMap(new HashMap<String, Integer>(),
36          MapConstraintsTest.TEST_CONSTRAINT);
37    }
38  
39    @Override protected Map<String, Integer> makePopulatedMap() {
40      final Map<String, Integer> sortedMap = MapConstraints.constrainedMap(
41          new HashMap<String, Integer>(), MapConstraintsTest.TEST_CONSTRAINT);
42      sortedMap.put("one", 1);
43      sortedMap.put("two", 2);
44      sortedMap.put("three", 3);
45      return sortedMap;
46    }
47  
48    @Override protected String getKeyNotInPopulatedMap()
49        throws UnsupportedOperationException {
50      return "minus one";
51    }
52  
53    @Override protected Integer getValueNotInPopulatedMap()
54        throws UnsupportedOperationException {
55      return -1;
56    }
57  
58    @Override public void testEntrySetRemoveAllNullFromEmpty() {
59      try {
60        super.testEntrySetRemoveAllNullFromEmpty();
61      } catch (RuntimeException tolerated) {
62        // GWT's HashMap.entrySet().removeAll(null) doesn't throws NPE.
63      }
64    }
65  
66    @Override public void testEntrySetRetainAllNullFromEmpty() {
67      try {
68        super.testEntrySetRetainAllNullFromEmpty();
69      } catch (RuntimeException tolerated) {
70        // GWT's HashMap.entrySet().retainAll(null) doesn't throws NPE.
71      }
72    }
73  
74    @Override public void testKeySetRemoveAllNullFromEmpty() {
75      try {
76        super.testKeySetRemoveAllNullFromEmpty();
77      } catch (RuntimeException tolerated) {
78        // GWT's HashMap.keySet().removeAll(null) doesn't throws NPE.
79      }
80    }
81  
82    @Override public void testKeySetRetainAllNullFromEmpty() {
83      try {
84        super.testKeySetRetainAllNullFromEmpty();
85      } catch (RuntimeException tolerated) {
86        // GWT's HashMap.keySet().retainAll(null) doesn't throws NPE.
87      }
88    }
89  
90    @Override public void testValuesRemoveAllNullFromEmpty() {
91      try {
92        super.testValuesRemoveAllNullFromEmpty();
93      } catch (RuntimeException tolerated) {
94        // GWT's HashMap.values().removeAll(null) doesn't throws NPE.
95      }
96    }
97  
98    @Override public void testValuesRetainAllNullFromEmpty() {
99      try {
100       super.testValuesRemoveAllNullFromEmpty();
101     } catch (RuntimeException tolerated) {
102       // GWT's HashMap.values().retainAll(null) doesn't throws NPE.
103     }
104   }
105 }